package com.db.server;

import com.db.domain.Cache;
import com.db.domain.Observable;
import com.db.domain.Observer;

import java.util.List;

public class Server implements Observable {
    private Cache cache;
    private List<Observer> observerList;

    public void setCache(Cache cache) {
        this.cache = cache;
        notifyObservers();
    }

    @Override
    public void addObserver(Observer o) {
        observerList.add(o);
    }

    @Override
    public boolean removeObserver(Observer o) {
        return observerList.remove(o);
    }

    @Override
    public void notifyObservers() {
        for (Observer o : observerList) {
            o.updateCache(cache);
        }
    }
}
